Skip to content

feat: Add has_reasoning flag to chat completion responses#7657

Open
AsadShahid04 wants to merge 1 commit intoai-dynamo:mainfrom
AsadShahid04:inf-54-reasoning-flag
Open

feat: Add has_reasoning flag to chat completion responses#7657
AsadShahid04 wants to merge 1 commit intoai-dynamo:mainfrom
AsadShahid04:inf-54-reasoning-flag

Conversation

@AsadShahid04
Copy link
Copy Markdown

@AsadShahid04 AsadShahid04 commented Mar 26, 2026

  • Add has_reasoning field to ChatChoice and ChatChoiceStream structs
  • Set has_reasoning to true when reasoning_content is present and non-empty
  • Helps clients identify responses that include reasoning content

Fixes #7154

Summary by CodeRabbit

  • New Features
    • Added support for chat responses to indicate whether reasoning content is included, providing better visibility into response composition and content type.

@AsadShahid04 AsadShahid04 requested a review from a team as a code owner March 26, 2026 09:52
@copy-pr-bot
Copy link
Copy Markdown

copy-pr-bot bot commented Mar 26, 2026

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@github-actions
Copy link
Copy Markdown
Contributor

👋 Hi AsadShahid04! Thank you for contributing to ai-dynamo/dynamo.

Just a reminder: The NVIDIA Test Github Validation CI runs an essential subset of the testing framework to quickly catch errors.Your PR reviewers may elect to test the changes comprehensively before approving your changes.

🚀

@github-actions github-actions bot added external-contribution Pull request is from an external contributor frontend `python -m dynamo.frontend` and `dynamo-run in=http|text|grpc` labels Mar 26, 2026
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 26, 2026

Walkthrough

The PR adds a has_reasoning optional boolean field to ChatChoice and ChatChoiceStream types to track whether reasoning content is present, and updates aggregation and delta generation logic to derive this field from the presence of reasoning_content.

Changes

Cohort / File(s) Summary
Async OpenAI Types
lib/async-openai/src/types/chat.rs
Added has_reasoning: Option<bool> field to both ChatChoice and ChatChoiceStream structs with conditional serialization, documented to indicate presence of reasoning content.
OpenAI Chat Completions
lib/llm/src/protocols/openai/chat_completions/aggregator.rs, lib/llm/src/protocols/openai/chat_completions/delta.rs
Updated conversion and generation logic to derive has_reasoning from presence and non-emptiness of reasoning_content, setting it to Some(true) when reasoning is present or None otherwise.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Linked Issues check ⚠️ Warning The PR adds a has_reasoning flag to identify responses with reasoning content, but does not address the core issue of missing content field when reasoning_content is present. Verify that the has_reasoning flag addition resolves issue #7154's root cause of missing content field, or clarify if additional fixes are needed separately.
Description check ❓ Inconclusive The description covers key changes and links to the issue, but lacks the Overview, Where to Review, and full Details structure specified in the template. Consider expanding the description to follow the template structure with an Overview section, detailed explanation of implementation, and specific file review guidance.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change—adding a has_reasoning flag to chat completion response types.
Out of Scope Changes check ✅ Passed All changes are scoped to adding the has_reasoning field to chat completion types and their construction logic; no unrelated modifications detected.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
lib/llm/src/protocols/openai/chat_completions/aggregator.rs (2)

442-448: ⚠️ Potential issue | 🔴 Critical

Missing has_reasoning field in test helper will cause compilation failure.

The ChatChoiceStream struct now requires the has_reasoning field, but the test helper at lines 442-448 doesn't include it. This will prevent the tests from compiling.

🐛 Proposed fix
         let choice = dynamo_async_openai::types::ChatChoiceStream {
             index,
             delta,
             finish_reason,
             stop_reason: None,
             logprobs,
+            has_reasoning: None,
         };
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@lib/llm/src/protocols/openai/chat_completions/aggregator.rs` around lines 442
- 448, The test helper constructing dynamo_async_openai::types::ChatChoiceStream
is missing the new required has_reasoning field; update the construction in
aggregator.rs (the ChatChoiceStream creation around
index/delta/finish_reason/logprobs) to include has_reasoning (true or false as
appropriate for the test case) so the struct initializer matches the updated
type and the tests compile.

666-693: ⚠️ Potential issue | 🔴 Critical

Missing has_reasoning field in test constructions.

These ChatChoiceStream constructions are also missing the new has_reasoning field and will fail to compile.

🐛 Proposed fix
                 dynamo_async_openai::types::ChatChoiceStream {
                     index: 0,
                     delta: dynamo_async_openai::types::ChatCompletionStreamResponseDelta {
                         role: Some(dynamo_async_openai::types::Role::Assistant),
                         content: Some(ChatCompletionMessageContent::Text("Choice 0".to_string())),
                         function_call: None,
                         tool_calls: None,
                         refusal: None,
                         reasoning_content: None,
                     },
                     finish_reason: Some(dynamo_async_openai::types::FinishReason::Stop),
                     stop_reason: None,
                     logprobs: None,
+                    has_reasoning: None,
                 },
                 dynamo_async_openai::types::ChatChoiceStream {
                     index: 1,
                     delta: dynamo_async_openai::types::ChatCompletionStreamResponseDelta {
                         role: Some(dynamo_async_openai::types::Role::Assistant),
                         content: Some(ChatCompletionMessageContent::Text("Choice 1".to_string())),
                         function_call: None,
                         tool_calls: None,
                         refusal: None,
                         reasoning_content: None,
                     },
                     finish_reason: Some(dynamo_async_openai::types::FinishReason::Stop),
                     stop_reason: None,
                     logprobs: None,
+                    has_reasoning: None,
                 },
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@lib/llm/src/protocols/openai/chat_completions/aggregator.rs` around lines 666
- 693, The test ChatChoiceStream constructions are missing the new has_reasoning
field and thus won't compile; update each
dynamo_async_openai::types::ChatChoiceStream literal (the ones with index: 0 and
index: 1) to include the has_reasoning field and set it to the appropriate
default for the type (e.g., has_reasoning: None if it's Option<bool> or
has_reasoning: false if it's a bool) so the struct literals for
ChatChoiceStream/ChatCompletionStreamResponseDelta compile.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@lib/llm/src/protocols/openai/chat_completions/delta.rs`:
- Around line 265-277: The has_reasoning computation is dead because
reasoning_content is hardcoded to None in create_choice; either accept
reasoning_content as a parameter to create_choice and set
delta.reasoning_content accordingly so the has_reasoning check
(delta.reasoning_content.as_ref().is_some_and(|r| !r.is_empty())) can reflect
real data, or remove the reasoning_content/has_reasoning logic entirely and stop
populating dynamo_async_openai::types::ChatChoiceStream.has_reasoning here;
update the create_choice signature and callers (or remove the check and related
field) and ensure consistency with components that currently populate
reasoning_content later (e.g., jail.rs, aggregator.rs).

---

Outside diff comments:
In `@lib/llm/src/protocols/openai/chat_completions/aggregator.rs`:
- Around line 442-448: The test helper constructing
dynamo_async_openai::types::ChatChoiceStream is missing the new required
has_reasoning field; update the construction in aggregator.rs (the
ChatChoiceStream creation around index/delta/finish_reason/logprobs) to include
has_reasoning (true or false as appropriate for the test case) so the struct
initializer matches the updated type and the tests compile.
- Around line 666-693: The test ChatChoiceStream constructions are missing the
new has_reasoning field and thus won't compile; update each
dynamo_async_openai::types::ChatChoiceStream literal (the ones with index: 0 and
index: 1) to include the has_reasoning field and set it to the appropriate
default for the type (e.g., has_reasoning: None if it's Option<bool> or
has_reasoning: false if it's a bool) so the struct literals for
ChatChoiceStream/ChatCompletionStreamResponseDelta compile.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 3d696228-fd02-486b-9396-08eb26b203dd

📥 Commits

Reviewing files that changed from the base of the PR and between 06f1701 and 4cf09b8.

📒 Files selected for processing (3)
  • lib/async-openai/src/types/chat.rs
  • lib/llm/src/protocols/openai/chat_completions/aggregator.rs
  • lib/llm/src/protocols/openai/chat_completions/delta.rs

@AsadShahid04 AsadShahid04 force-pushed the inf-54-reasoning-flag branch from 4cf09b8 to 88938f0 Compare March 27, 2026 00:47
- Add has_reasoning field to ChatChoice and ChatChoiceStream structs
- Set has_reasoning to true when reasoning_content is present and non-empty
- Helps clients identify responses that include reasoning content

Fixes ai-dynamo#7154

Signed-off-by: Asad Shahid <[email protected]>
@AsadShahid04 AsadShahid04 force-pushed the inf-54-reasoning-flag branch from 88938f0 to 076c910 Compare March 27, 2026 00:49
@rmccorm4
Copy link
Copy Markdown
Contributor

Hi @AsadShahid04 , thanks for the contribution. I don't think we need a new Boolean field to identify this, we can instead fix the root of the problem by making sure the content field is always present in the response, even if an empty string.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

external-contribution Pull request is from an external contributor feat frontend `python -m dynamo.frontend` and `dynamo-run in=http|text|grpc` size/S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG]: Missing 'content' in response while 'reasoning_content' is present for gpt-oss-120B

2 participants